class flyRoute {
  constructor(viewer) {
    this.viewer = viewer
    //创建飞行管理对象
    this.flyManager = null;
  }

  pause() {
    this.flyManager && this.flyManager.pause();
  };

  stop () {
    this.flyManager && this.flyManager.stop();
  };

  play() {
    if (this.flyManager) {
      this.flyManager.play();
    } else {
      var scene = this.viewer.scene;
      var routes = new Cesium.RouteCollection(this.viewer.entities);
      var fileInput = document.getElementById("flyFile");
      var file = fileInput.files[0];
      if(!file){
        return; // 没有选择fpf文件无法开始执行
      }
      var reader = new FileReader();
      reader.onload = function (e) { // 读取操作完成时出发
        var XMLContent = e.target.result;
        routes.fromXML(XMLContent);
      };
      reader.readAsBinaryString(file);
      //创建飞行管理对象
      this.flyManager = new Cesium.FlyManager({
        scene: scene,
        routes: routes
      });
      this.flyManager.stopArrived.addEventListener((routeStop)=> {
        routeStop.waitTime = 1;
      });
      if (this.flyManager.readyPromise) {
        Cesium.when(this.flyManager.readyPromise,  ()=> {
          // var currentRoute = this.flyManager.currentRoute;
          // currentRoute.isLineVisible = true;
          // currentRoute.isStopVisible = true;
          this.flyManager.play();
        });
      }
    }
  };
}
export { flyRoute }
